package com.omuao.message.queue.utils;

import org.rocksdb.Options;
import org.rocksdb.RocksDB;
import org.rocksdb.RocksDBException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;

/**
 * @author Administrator
 */
public class RocksDbUtils {

    public static Logger logger = LoggerFactory.getLogger(RocksDbUtils.class);

    /**
     * 构建Rocks Db
     *
     * @param path 路径
     * @return RocksDb
     * @throws IOException 输入输出异常
     */
    public static RocksDB build(String path) throws IOException {
        Options options = new Options();
        options.setCreateIfMissing(true);
        File file = new File(path);
        RocksDB db = null;
        try {
            db = RocksDB.open(options, file.getPath());
        } catch (RocksDBException e) {
            logger.error(e.getMessage(), e);
        }
        return db;
    }

}
